package igou.togogo.controller;

import igou.togogo.pojo.EgouResult;
import igou.togogo.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    IProductService productService;


    @RequestMapping("/list")
    @ResponseBody
    public EgouResult getProductByBrandId(Integer brandId,
                                          Integer page,
                                          Integer rows){
        EgouResult result = productService.getProductByBrandId(brandId, page, rows);
        return result;
    }


    @RequestMapping("/detail/{id}")
    @ResponseBody
    public EgouResult getProductDetail(@PathVariable("id") Integer id,
                                       @RequestParam(value = "color_id",required = false,defaultValue = "") String colorId){
        return productService.getProductDetail(id,colorId);

    }

    @RequestMapping("/{id}")
    @ResponseBody
    public EgouResult getById(@PathVariable("id") Integer id) {
        return productService.getById(id);
    }
}
